package com.life.ai.server.modules.system.entity;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.*;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;

/**
 * <p>
 * 菜单权限
 * </p>
 *
 * @author kyle
 * @since 2024-06-14
 */
@Getter
@Setter
@Accessors(chain = true)
@TableName("sys_menu")
@ApiModel(value = "SysMenu对象", description = "菜单权限")
public class SysMenu implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("菜单id")
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private Long id;

    @ApiModelProperty("父菜单ID")
    @TableField("parent_id")
    private Long parentId;

    @ApiModelProperty("菜单名称")
    @TableField("menu_name")
    private String menuName;

    @ApiModelProperty("菜单类型（1菜单 2按钮）")
    @TableField("menu_type")
    private String menuType;

    @ApiModelProperty("菜单图标")
    @TableField("icon")
    private String icon;

    @ApiModelProperty("排序")
    @TableField("sort")
    private Integer sort;

    @ApiModelProperty("菜单权限标识")
    @TableField("permission")
    private String permission;

    @ApiModelProperty("显示状态（1显示 2隐藏）")
    @TableField("visible")
    private String visible;

    @ApiModelProperty("启用状态（1启用 2停用）")
    @TableField("status")
    private String status;

    @ApiModelProperty("删除标志（0正常 1删除）")
    @TableField("is_deleted")
    @TableLogic
    private Boolean isDeleted;

    @ApiModelProperty("创建人")
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private Long createBy;

    @ApiModelProperty("创建时间")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    @ApiModelProperty("修改人")
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private Long updateBy;

    @ApiModelProperty("修改时间")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    @ApiModelProperty(value = "上级菜单(面包屑)")
    @TableField(exist = false)
    private String parentMenus;

    public SysMenu addParentMenus(SysMenu SysMenu) {
        if (StrUtil.isNotBlank(SysMenu.getParentMenus())){
            this.parentMenus = SysMenu.getParentMenus() + "," + SysMenu.getId();
        }else {
            this.parentMenus = SysMenu.getId().toString();
        }
        return this;
    }
}
